package com.escafoide.smm;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class Login extends Activity {
	Button aceptar;
	EditText user;
	EditText pass;
	Context mContext;
	SharedPreferences sp;
	SharedPreferences.Editor spe;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);
		initViews();
		initOnClick();
	}

	private void initViews() {
		aceptar = (Button) findViewById(R.id.button1);
		user = (EditText) findViewById(R.id.identificacion);
		pass = (EditText) findViewById(R.id.numeroSecreto);
		mContext = this;
		user.setText("47846753");
		pass.setText("123456");
		
		sp = mContext.getSharedPreferences("SMM",
				Context.MODE_PRIVATE);
		spe = sp.edit();
	}

	private void initOnClick() {
		aceptar.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent i;
				if (sp.getString("first_time", null) == null){
					spe.putString("first_time", "ooo");
					spe.commit();
					i = new Intent(mContext, Config.class);
					i.putExtra("from","Login");
					startActivity(i);
					finish();
				} else {
					i = new Intent(mContext, graphs.class);
					startActivity(i);
					finish();
				}
			}
		});
	}

}
